//
//  BNBaseCollectionListView.m
//  BNCodeGuide
//
//  Created by Mac on 2021/5/22.
//  Copyright © 2021 kevin007. All rights reserved.
//

#import "BNBaseCollectionListView.h"

@implementation BNBaseCollectionListView
- (instancetype)initWithFrame:(CGRect)frame {
    if ([super initWithFrame:frame]) {
        [self setupUI];
    }
    
    return self;
}

#pragma mark - ----------------Public Methods----------------
#pragma mark - ----------------RefreshUI----------------
- (void)refreshUI {
    [self.collectionView reloadData];
}

#pragma mark - ----------------Private Methods----------------
#pragma mark - setupUI
- (void)setupUI{
    self.backgroundColor = [UIColor whiteColor];
    
    [self addSubview:self.collectionView];
    [self addLayouts];
}

#pragma mark - ----------------AddLayouts----------------
- (void)addLayouts {
    [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_offset(0);
    }];
}

#pragma mark - -------------UICollectionViewDataSource----------------
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 0;
}

- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    return [UICollectionViewCell cellFromClassWithCollectionView:collectionView forIndexPath:indexPath];
}

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
    return nil;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section {
    return CGSizeZero;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section {
    return CGSizeZero;
}

#pragma mark - -------------UICollectionViewDelegate----------------
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    
    !self.didSelectItemAtIndexPathHandler?:self.didSelectItemAtIndexPathHandler(indexPath);
    
    if ([self.delegate respondsToSelector:@selector(collectionListView:didSelectItemAtIndexPath:)]) {
        [self.delegate collectionListView:self didSelectItemAtIndexPath:indexPath];
    }
}

#pragma mark - ----------------Getter & Setter----------------
- (UICollectionViewFlowLayout *)flowLayout {
    if (!_flowLayout) {
        _flowLayout = [UICollectionViewFlowLayout new];
        _flowLayout.sectionInset = UIEdgeInsetsZero;
        _flowLayout.itemSize = CGSizeMake(UIScreen.width, UIScreen.height);
        _flowLayout.minimumLineSpacing = 0.0;
        _flowLayout.minimumInteritemSpacing = 0.0;
        
    }
    
    return _flowLayout;
}

- (UICollectionView *)collectionView {
    if (!_collectionView) {
        _collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:self.flowLayout];
        _collectionView.backgroundColor = [UIColor whiteColor];
        _collectionView.dataSource = self;
        _collectionView.delegate = self;

    }
    
    return _collectionView;
}
@end
